package com.example.demo.repository;

import com.example.demo.entity.User;
import com.example.demo.entity.vo.UserVO;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.querydsl.QuerydslPredicateExecutor;

import javax.annotation.Resource;
import java.util.List;

@Resource
public interface UserRepository extends JpaRepository<User, Long>, JpaSpecificationExecutor<User>, QuerydslPredicateExecutor<User> {

    @Query(value = "select u.username,u.user_age,r.role_name from t_user u left join t_role r on u.role_id = r.role_id where u.user_id=?", nativeQuery = true)
    List<UserVO> selectUserWithRoleByUserId(long userId);


}
